﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace MvcApplication1.Controllers
{
    public class AccountController : Controller
    {
        //
        // GET: /Account/
    [HttpGet ]
        public ActionResult LogOn()
        {
            return View();
        }

    [HttpPost]
    public ActionResult Login(MvcApplication1.Models.LoginModel model)
    {
        if (ModelState.IsValid)
        {
            if (model.IsValid(model.UserLogin, model.Password))
            {
                FormsAuthentication.SetAuthCookie(model.UserLogin, model.RememberMe);
                return RedirectToAction("Index", "Home");
            }
            else ModelState.AddModelError("", "The user name or password provided is incorrect");
        }
        return View(model);
    }

    public ActionResult LogOut()
    {
        FormsAuthentication.SignOut();
        return RedirectToAction("Index", "Home");
    }
    }
}
